package util;

import java.util.function.IntSupplier;

public class FlowUtil {

    public static void silent(final Procedure procedure) {

        try { procedure.apply(); } catch (Exception e) { e.printStackTrace(); }
    }

    public static <T> void silent(final T value, final IConsumer<T> consumer) {

        try { consumer.apply(value); } catch (Exception e) { e.printStackTrace(); }
    }

    public static <T> T silent(final ISupplier<T> supplier, final T orElse) {

        try { return supplier.apply(); } catch (Exception e) {

            e.printStackTrace();

            return orElse;
        }
    }

    @FunctionalInterface
    public interface Procedure {

        void apply() throws Exception;
    }

    @FunctionalInterface
    public interface IConsumer<T> {

        void apply(T value) throws Exception;
    }

    @FunctionalInterface
    public interface ISupplier<T> {

        T apply() throws Exception;
    }
}
